<template>
  <!--    布局容器-->
  <el-container style="height: 100%;">
    <!--      头部容器-->
    <el-header class="home-header">
      <div class="header-title">未闻花名</div>
      <div class="userinfo">
        <el-dropdown @command="handleCommand">
          <div style="display: flex;flex-direction:column;justify-content: center;align-items: center">
            <el-avatar
                :size="45"
                :src=userImgUrl
                alt="用户头像"
            >
              <img
                  src="https://cube.elemecdn.com/e/fd/0fc7d20532fdaf769a25683617711png.png"
                  alt="空白头像"
              />
            </el-avatar>
            <span
                class="username"
                style="font-size:0.9rem;color: black;margin-top: 6px"
            >
              {{ username }}<i class="el-icon-arrow-down el-icon--right"></i>
            </span>
          </div>
          <template #dropdown>
            <el-dropdown-menu>
              <el-dropdown-item command="setting">个人设置</el-dropdown-item>
              <el-dropdown-item command="logout">注销登录</el-dropdown-item>
            </el-dropdown-menu>
          </template>

        </el-dropdown>

      </div>
    </el-header>

    <el-container>
      <!--        侧边栏容器-->
      <el-aside
          class="aside"
      >
        <el-menu
            router
            unique-opened
        >
          <el-submenu
              :index="index + ''"
              v-for="(item,index) in router"
              :key="index"
          >
            <template #title>
              <i
                  :class="item.iconCls?item.iconCls:'el-icon-setting'"
                  style="margin-right: 10px;color: #00ace5"
              ></i>
              <span>{{ item.name }}</span>
            </template>
            <el-menu-item
                v-for="(children,index2) in item.children"
                :index="children.path"
                :key="index2"
            >
              <span>{{ children.name }} </span>
            </el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>
      <!-- 主体功能区 -->
      <el-main>
        <el-breadcrumb
            separator-class="el-icon-arrow-right"
            v-if="this.$route.path !== '/home'"
        >
          <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
          <el-breadcrumb-item>{{ this.$route.name }}</el-breadcrumb-item>
        </el-breadcrumb>
        <div
            class="home-welcome"
            v-else
        >欢迎来到未闻花名</div>
        <router-view class="home-router-view" />
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
import {mapState} from 'vuex'

export default {
  name: "Home",
  data() {
    return {
      userImgUrl: window.sessionStorage.getItem('userImgUrl'),
      username: window.sessionStorage.getItem('user')
    }
  },
  computed: {
    ...mapState({
      router: (store) => store.routes
    }),
    routes() {
      console.log($store._state.data.routes)
      return $store._state.data.routes;
    }
  },
  methods: {
    handleCommand(command) {
      this.$message('click on item ' + command);
    }
  },
  created() {
    console.log('home-vue开始创建了11111')
  },
  beforeMount() {

  }
}
</script>

<style lang="less" scoped>

.home-header {
  width: 100%;
  height: min-content !important;
  background: #80ccde;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-sizing: border-box;
}

.home-header .header-title {
  font-family: 华文行楷, serif;
  font-size: 1.8rem;
}

.home-header .userinfo {
  cursor: pointer;
  margin: 10px;
}

.home-header .userinfo img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
}

.el-menu-vertical-demo {
  width: 200px;
  min-height: 400px;
}

.el-menu {
  height: 100%;
  border: none;
}

.el-dropdown-link {
  cursor: pointer;
  color: #409EFF;
  font-size: 24px;
}

.el-icon-arrow-down {
  font-size: 12px;
}

.home-welcome {
  margin: 40px auto;
  text-align: center;
  font-family: 华文行楷, monospace;
  font-size: 6.6rem;
  color: #80ccde;
}
.home-router-view {
  width: 100%;
  margin-top: 10px;
}
.el-dropdown-menu__item:focus,
.el-dropdown-menu__item:not(.is-disabled):hover {
  //background: #00ace5 !important;
  transition: background 0.2s;
  opacity: 0.8;
}
</style>